package com.itheima.polymorphsm1;

public class Test {
    public static void main(String[] args) {
        //对象多态
        Animal a1 = new Tortoise();
        Animal a2 = new Wolf();

        //行为多态：编译看左边，运行看右边
        a1.run(); //先看左边Animal有无该方法，运行则运行右边类中的方法
        a2.run();

        //成员变量：编译看左边，运行看左边
        System.out.println(a1.name);
        System.out.println(a2.name);

        if(a1 instanceof Wolf){
            Wolf a3 = (Wolf) a1;
            a3.eat();
        }

        //多态的好处
        go(a1);
        go(a2);
    }

    public static void go(Animal a){
        System.out.println(a.name);
        a.run();
    }
}
